#ifndef __HardwareIndexBuffer__
#define __HardwareIndexBuffer__


#include "U2PreRequest.h"
#include "U2HardwareBuffer.h"
#include "U2SharedPtr.h"


U2EG_NAMESPACE_BEGIN


class U2HardwareBufferManagerBase;


/** Specialisation of U2HardwareBuffer for vertex index buffers, still abstract. */
class _U2Share U2HardwareIndexBuffer : public U2HardwareBuffer
{
    public:
	    enum IndexType {
		    IT_16BIT,
		    IT_32BIT
	    };

    protected:
		U2HardwareBufferManagerBase* mMgr;
	    IndexType mIndexType;
	    size_t mNumIndexes;
        size_t mIndexSize;

    public:
	    /// Should be called by HardwareBufferManager
	    U2HardwareIndexBuffer(U2HardwareBufferManagerBase* mgr, IndexType idxType, size_t numIndexes, U2HardwareBuffer::Usage usage,
            bool useSystemMemory, bool useShadowBuffer);
        ~U2HardwareIndexBuffer();
		/// Return the manager of this buffer, if any
		U2HardwareBufferManagerBase* getManager() const { return mMgr; }
		/// Get the type of indexes used in this buffer
        IndexType getType(void) const { return mIndexType; }
        /// Get the number of indexes in this buffer
        size_t getNumIndexes(void) const { return mNumIndexes; }
        /// Get the size in bytes of each index
        size_t getIndexSize(void) const { return mIndexSize; }

	    // NB subclasses should override lock, unlock, readData, writeData
};


/** Shared pointer implementation used to share index buffers. */
class _U2Share U2HardwareIndexBufferSharedPtr : public U2SharedPtr<U2HardwareIndexBuffer>
{
public:
    U2HardwareIndexBufferSharedPtr() : U2SharedPtr<U2HardwareIndexBuffer>() {}
    explicit U2HardwareIndexBufferSharedPtr(U2HardwareIndexBuffer* buf);
};


U2EG_NAMESPACE_END


#endif

